#!/usr/bin/env Python
# coding=utf-8

import handlers.base as baseHandler
import json
class GetOpenIDHandler(baseHandler.BaseHandler):
    def get(self):
        self.post()
    def post(self):
        data = json.loads(self.request.body)
        appid = data['appid']
        secret = data['secret']
        grant_type = data['grant_type']
        js_code = data['js_code']
        import urllib.request
        page = urllib.request.urlopen(
            "https://api.weixin.qq.com/sns/jscode2session?appid="+appid+"&secret="+secret+"&grant_type="+grant_type+"&js_code="+js_code)
        lines = page.readlines()
        self.write(lines[0])